<?php
require_once dirname(__FILE__).'/include.php';
Master::loadCoreClass("AdminControl");
$Admin = new AdminControl();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?=Config::$siteName ?></title>    
<?php
require_once dirname(__FILE__).'/heard.php';
?> 
</head>
<body>
<?php
if (Get::getByKey('action')=='save')
{		
	//$mydb->db->delete('tableitems',array('tableName'=>Post::getByKey('tableName')));
	//$mydb->db->insert('tableitems',array('tableNameCN'=>Post::getByKey('tableNameCN'),'tableName'=>Post::getByKey('tableName')));
	$Admin->edittableitems();
	//Header("Location:adminhelper.php");
}else if(Get::getByKey('action')=='create' && Post::getByKey('tableName')!='')
{
	$Admin->execute("CREATE TABLE `".Post::getByKey('tableName')."` (`id` int(11) NOT NULL auto_increment,PRIMARY KEY  (`id`))");
	$Admin->insert('tableitems',array('tableNameCN'=>Post::getByKey('tableNameCN'),'tableName'=>Post::getByKey('tableName')));
	Header("Location:adminhelper.php");
}else if(  Get::getByKey('action')=='del'){
  $Admin->deltableitems(Get::getByKey('id'));
}
$Ar = $Admin->showTables();
//print_r($Ar);
foreach($Ar as $key)
{
	//echo count($mydb->db->select('tableitems',array('tableName'=>$key['Name'])));
	if (count($Admin->select('tableitems',array('tableName'=>$key['Name'])))<1)
		$Admin->insert('tableitems',array('tableName'=>$key['Name']));	
}
$Arr = $Admin->showtableitems(array('showpage'=>1));
?>
<div id="main-content">		
				<div class="content-box">
				<div class="content-box-header">					
					<h3>当前位置：<?=Config::$siteName ?>管理系统 &gt; 开发助手</h3>					
					<ul class="content-box-tabs">
						<li><a href="#tab1" class="default-tab">列表</a></li>
					</ul>					
					<div class="clear"></div>					
				</div> 
				<div class="content-box-content">				
					<div class="tab-content default-tab" id="tab1"> 											
						<table>							
							<thead>
								<tr>
								   <th>数据表名称</th>
								   <th>中文名称</th>
								   <th>管理&nbsp;&nbsp;</th>								   
								</tr>
							</thead>
							<tfoot>
								<tr>
									<td colspan="3">		
									<?=$Admin->showPages()?>								
									</td>
								</tr>
							</tfoot>
							<tbody>
   <?php
		foreach($Arr as $key){
    ?> 					<form action="?action=save" method="post">
								<tr>
									<td><?=$key->tableName?></td>
									<td>
									<input type="hidden" id="tableName" name="tableName"  value="<?=$key->tableName?>" />
									<input type="hidden" id="id" name="id"  value="<?=$key->id?>" />
									<input class="text-input medium-input" type="text" id="tableNameCN" name="tableNameCN" value="<?=$key->tableNameCN?>" /></td>		
									<td>
									<input  type="submit"  value="更新"/>
									<a href="?action=del&id=<?=$key->id?>" title="Delete"><img src="images/icons/cross.png" alt="Delete" /></a>									
										 <a href="adminhelpermod.php?tableName=<?=$key->tableName?>" title="Edit"><img src="images/icons/pencil.png" alt="Edit" /></a>
										 <a href="databasehelper.php?tableName=<?=$key->tableName?>" title="数据库管理"><img src="images/icons/hammer_screwdriver.png" alt="数据库管理" /></a>
										 <a action="createnode" href="adminsetup2.php?action=createnode&tableName=<?=$key->tableName?>&tableNameCN=<?=$key->tableNameCN?>" title="数据库管理">创建权限节点</a>
										 <a action="createcontrol" href="adminsetup2.php?action=createcontrol&tableName=<?=$key->tableName?>" title="生成控制器">生成控制器</a>				 
									</td>
								</tr>		
								</form>												
	<?
		}
    ?> 					
							<form action="?action=create" method="post">
								<tr>
									<td><input class="text-input medium-input" type="text" id="tableName" name="tableName" /></td>
									<td>
									<input class="text-input medium-input" type="text" id="tableNameCN" name="tableNameCN" /></td>							
									<td>
									<input  type="submit"  value="创建"/>													 
									</td>
								</tr>	
								</form>
							</tbody>
						</table>		
					</div>
					
				</div> 
</div>
</div>

</body>  
</html>
<script type="text/javascript">
	$(function() {
		$("a[action]").each(function(){
				var url = $(this).attr('href');
				$.get(url+'&check=check', function(data){
					if ($.trim(data)=='ok')
						$("a[href="+url+"]").remove();
				});			
			});
		$("a[action]").click(function(){
				var url = $(this).attr('href');
				$.get(url,function(data){
					if ($.trim(data)=='ok')
					{
						alert('操作成功');
						$("a[href="+url+"]").remove();
					}				
				});	
				return false;		
			});			
	});
</script>
